package kis.google.guava;

import java.util.concurrent.TimeUnit;

import org.junit.Test;

import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;

public class TestModule {
	@Test//测试校验  计时器
	public void checkArgumentTest(){
		Stopwatch stopwatch = Stopwatch.createUnstarted().start();
		try
		{
			Preconditions.checkArgument(true,"为空");
		} catch (Exception e)
		{
			System.out.println(e.getMessage());
		}
		long nanos = stopwatch.elapsed(TimeUnit.MILLISECONDS);
		System.out.println(nanos);
	}
	@Test
	public void stringTest(){
		//类对比
		String test= "afaf";
		String test1= "";
		String test2=null;
		System.out.println(Objects.equal(test2, null));
		//split
		String split="a,b,,c,";
		String[] ss=split.split(",");
		for (String string : ss)
		{
			System.out.println(string);
		}
		Iterable<String> ss1 = Splitter.on(",").trimResults().omitEmptyStrings().split(split);
		for (String string : ss1)
		{
			System.out.println(string);
		}
		//字符串添加
		Joiner joiner = Joiner.on(",").skipNulls();
		System.out.println(joiner.join("Harry",null,"Ron"));
		//测试为空
		String s= "  ";
		String s1=null;
		String s2 = "";
		System.out.println(Strings.isNullOrEmpty(s));
		System.out.println(Strings.isNullOrEmpty(s1));
		System.out.println(Strings.isNullOrEmpty(s2));
		//字符串比较
		//比较相同部门的前缀
		System.out.println(Strings.commonPrefix("www.baidu.com", "www.baidu.net"));
		//比较相同部分的后缀
		System.out.println(Strings.commonSuffix("www123", "weeeww123"));
		//null ""转换
		System.out.println(Strings.nullToEmpty(null));
		//字符串不足位数补充 比如 4.0 --》4.000
		char c = '0';
		System.out.println(Strings.padEnd("4.0", 5, c));
		//从前面追加
		System.out.println(Strings.padStart("4.0", 5, c));
	}
}
